package org.scirp.ijmis.dao.personpaper.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.scirp.ijmis.dao.base.impl.BaseDAOImpl;
import org.scirp.ijmis.dao.personpaper.ISurveyChoiceOfPersonDAO;
import org.scirp.ijmis.po.personpaper.SurveyChoiceOfPerson;

public class SurveyChoiceOfPersonDAOImpl extends BaseDAOImpl<SurveyChoiceOfPerson> implements ISurveyChoiceOfPersonDAO {

	private static final String className = SurveyChoiceOfPersonDAOImpl.class.toString();

	public List<SurveyChoiceOfPerson> selectAll() {

		String hql = "from SurveyChoiceOfPerson order by pid desc";
		return super.ExecuteQuery(hql, className + "-->selectAll");
	}

	public Long countObject() {
		return super.countObject(className + "-->selectAll");
	}
	public Long countObjectByChoiceId(Long ChoiceId) {
		String hql="select count(distinct person.pid) from SurveyChoiceOfPerson where surveyChoice.pid=:ChoiceId";
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("ChoiceId", ChoiceId);
		return (Long) super.selectSingle(hql, map, className+"-->countObjectByChoiceId(Long ChoiceId)");
	}
	
	
	public Long countObjectBySurveyId(Long surveyId) {
		String hql="select count(distinct person.pid) from SurveyChoiceOfPerson where surveyChoice.survey.pid=:surveyId";
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("surveyId", surveyId);
		return (Long) super.selectSingle(hql, map, className+"-->countObjectBySurveyId(Long surveyId)");
	}
	public SurveyChoiceOfPerson selectById(Object id) {

		return (SurveyChoiceOfPerson) super.selectById(id, className + "-->selectById");
	}

	public long saveSurveyChoiceOfPerson(SurveyChoiceOfPerson entity) {
		return super.saveObject(entity, className + "-->saveSurveyChoiceOfPerson(SurveyChoiceOfPerson entity)");
	}

	public boolean updateSurveyChoiceOfPerson(SurveyChoiceOfPerson entity) {
		return super.updateObject(entity, className + "-->updateSurveyChoiceOfPerson(SurveyChoiceOfPerson entity)");
	}

	public SurveyChoiceOfPerson deleteSurveyChoiceOfPerson(SurveyChoiceOfPerson entity) {
		return super.deleteObject(entity, className + "-->deleteSurveyChoiceOfPerson(SurveyChoiceOfPerson entity)");
	}

	
	public boolean deleteSurveyChoiceOfPersonByPersonId(Long personId) {
		String hql="delete from SurveyChoiceOfPerson where personId=:personId";
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("personId", personId);
		return super.ExecuteNonQuery(hql, map, className+"-->deleteSurveyChoiceOfPersonByPersonId(Long personId)");
	}
	public boolean deleteSurveyChoiceOfPersonByPersonIdAndSureyId(Long personId,Long surveyId) {
		String hql="delete from SurveyChoiceOfPerson where personId=:personId and surveyChoiceId in (select pid from SurveyChoice where surveyId=:surveyId)";
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("personId", personId);
		map.put("surveyId", surveyId);
		return super.ExecuteNonQuery(hql, map, className+"-->deleteSurveyChoiceOfPersonByPersonIdAndSureyId(Long personId,Long surveyId)");
	}
	public List<SurveyChoiceOfPerson> selectSurveyChoiceOfPersonByPersonId(Long personId) {
		String hql = "from SurveyChoiceOfPerson where personId=" + personId ;
		return super.select(hql, 0, 0, className + "-->selectSurveyChoiceOfPersonBypersonId(Long personId)");

	}

	public List<SurveyChoiceOfPerson> selectSurveyChoiceOfPersonBySurveyChoiceId(Long surveyChoiceId) {
		String hql = "from SurveyChoiceOfPerson where surveyChoice.pid=" + surveyChoiceId;
		return super.select(hql, 0, 0, className + "-->selectSurveyChoiceOfPersonBySurveyChoiceId(Long surveyChoiceId)");
	}
}
